<template>
  <div>
      <h1>登录</h1>
      <van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="用户名"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="密码"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit" @click="onClickLoginD">
      提交
    </van-button>
  </div>
</van-form>
  </div>
</template>

<script>
import Vue from 'vue';
import { Toast } from 'vant';

Vue.use(Toast);
import axios from "axios";
export default {
    data(){
        return{
            username:'',
            password:''
        }
    },
    mounted(){
     
    },
    methods:{
        onSubmit(){
             console.log(123);
        },
       onClickLoginD(){
              axios.get("https://api.it120.cc/small4/user/m/login?deviceId=007&deviceName=monkey",{
            params:{
                mobile:this.username,
                pwd:this.password
            }
        }).then((res)=>{
            console.log(res);
            if(res.data.code == 500){
                Toast.fail('登录失败!');
                return;
            }else if(res.data.code == 0){
                localStorage.setItem('token',JSON.stringify(res.data.data.token));
                Toast.success('登录成功');
                this.$router.push(this.$myRouter.PathConfig.USER);
            }
        }).catch((error)=>{
            console.log(error);
        })
       }
    }
}
</script>

<style>

</style>